BBCode scripting
mdCMS uses BBcode (BBCode at Wikipedia). You can create your own BBCode functions in PHP. This means that you can modify the given texts with all possibilities that PHP gives you (Regular Expressions ...) How to start In mdCMS we use a text converter to convert the texts. This means that we clean out all HTML Code (To prevent users adding Javascripts or other bad things). Next step is to replace strings like :D or :) with the matching smilie images (See smilies for more informations) After that all BBCode functions are called. BBCode is used to define what HTML code is allowed. In mdCMS you can add your own BBCode replacing functions written in PHP. mdCMS reads the /bbcode/ directory and calls one file after the other (See Functions name / Filename) (The plugin itself defines if the text should be converted with BBCode, with smilies or only nl2br() and htmlentities(). nl2br() and htmlentities() are always used to protect from Javascripts or other bad things.) Scripting reference BBCode functions in mdCMS require a file that is named like this: "{function_name}.bbcode.inc.php" The PHP file itself has to look like this: The variable $text is the whole text that has to be BBCoded. All PHP Functions may be used. Please note that smilies, nl2br() and htmlentities() are converted before any BBCode modification. Functions name / Filename It is important that you use the same name for {function_name} inside the *.bbcode.inc.php and in its filename. The name of your BBCode function can be anything except Functions that are already existing in mdCMS or default PHP Functions. To make sure that your custom BBCode functions name is not used elsewhere in mdCMS you should always name your functions with the prefix "bbcode_" Of course the function and filename has to be a valid filename. Also see the PHP documentation about functions. Include into a website To include your custom BBCode function into a website, you only have to put the *.bbcode.inc.php into the /bbcode/ directory in the mdCMS root. Adding buttons to the mdCMS textbox toolbar You can also add buttons to past your BBCode into the textbox. mdCMS provides a toolbar for BBCodes and smilies. More info about the Textbox toolbar scripting. Examples Here you can find a few examples of BBCode scripts for mdCMS. Please note that all these BBCodes are already in mdCMSs default bbocde. Example 1: b i u s This example will replace b /b with | i /i with | u /u with | s /s with It uses an easy regular expression to replace the BBCode with HTML Code. Filename: "bbcode_bius.bbcode.inc.php" \\1", $text); $text = preg_replace("/\i\(.*?)\\/i\/si", "\\1", $text); $text = preg_replace("/\u\(.*?)\\/u\/si", "\\1", $text); $text = preg_replace("/\s\(.*?)\\/s\/si", "\\1", $text); return $text; //Give back the $text variable } ?> Example 2: color This example will replace color with the matching HTML strings. The used regular expression is a little bit harder to understand than the one used in example 1. Filename: "bbcode_color.bbcode.inc.php" \\2", $text); return $text; //Give back the $text variable } ?>